﻿using System;
namespace Producers.Liiklusregister.Xtee.Riik.Ee.Producer.Liiklusregister {
    
    
    [global::Xtee.Core.Attributes.XmlTypeAttribute(Name="ylevaatus", Namespace="http://producers.liiklusregister.xtee.riik.ee/producer/liiklusregister", Target=typeof(Ylevaatus))]
    public class YlevaatusSerializer : global::Xtee.Core.Types.AbstractXteeSerializable {
        
        protected IYlevaatus clazz;
        
        public YlevaatusSerializer(IYlevaatus clazz) {
            this.clazz = clazz;
        }
        
        public override void WriteXml(global::Xtee.Core.IXteeXmlWriter Writer) {
            base.WriteXml(Writer);
            Writer.WriteStartElement("yv_liik");
            if (clazz.YvLiik!=null) {
                Writer.WriteTypeAttribute("http://www.w3.org/2001/XMLSchema", "string");
                Writer.WriteString(new global::Xtee.Core.Schema.XsdString(((string)(clazz.YvLiik))).ToString());
            }
            else {
                throw new global::Xtee.Core.Exceptions.NillableNotAllowedException("Nullable is not allowed for element : YvLiik");
            }
            Writer.WriteEndElement();
            Writer.WriteStartElement("yv_kp");
            if (clazz.YvKp!=null) {
                Writer.WriteTypeAttribute("http://www.w3.org/2001/XMLSchema", "string");
                Writer.WriteString(new global::Xtee.Core.Schema.XsdString(((string)(clazz.YvKp))).ToString());
            }
            else {
                throw new global::Xtee.Core.Exceptions.NillableNotAllowedException("Nullable is not allowed for element : YvKp");
            }
            Writer.WriteEndElement();
            Writer.WriteStartElement("jargm_yv_kp");
            if (clazz.JargmYvKp!=null) {
                Writer.WriteTypeAttribute("http://www.w3.org/2001/XMLSchema", "string");
                Writer.WriteString(new global::Xtee.Core.Schema.XsdString(((string)(clazz.JargmYvKp))).ToString());
            }
            else {
                throw new global::Xtee.Core.Exceptions.NillableNotAllowedException("Nullable is not allowed for element : JargmYvKp");
            }
            Writer.WriteEndElement();
            Writer.WriteStartElement("yv_markus");
            if (clazz.YvMarkus!=null) {
                Writer.WriteTypeAttribute("http://www.w3.org/2001/XMLSchema", "string");
                Writer.WriteString(new global::Xtee.Core.Schema.XsdString(((string)(clazz.YvMarkus))).ToString());
            }
            else {
                throw new global::Xtee.Core.Exceptions.NillableNotAllowedException("Nullable is not allowed for element : YvMarkus");
            }
            Writer.WriteEndElement();
            Writer.WriteStartElement("rikked");
            if (clazz.Rikked!=null) {
                global::Xtee.Core.SerializationMetadata metaRikked = this.GetMetaData(clazz.Rikked);
                Writer.WriteTypeAttribute(metaRikked.TypeQualifiedName.Namespace, metaRikked.TypeQualifiedName.Name);
                metaRikked.NewSerializer(clazz.Rikked).WriteXml(Writer);
            }
            else {
                throw new global::Xtee.Core.Exceptions.NillableNotAllowedException("Nullable is not allowed for element : Rikked");
            }
            Writer.WriteEndElement();
            Writer.WriteStartElement("rikete_info");
            if (clazz.RiketeInfo!=null) {
                Writer.WriteTypeAttribute("http://www.w3.org/2001/XMLSchema", "string");
                Writer.WriteString(new global::Xtee.Core.Schema.XsdString(((string)(clazz.RiketeInfo))).ToString());
            }
            else {
                throw new global::Xtee.Core.Exceptions.NillableNotAllowedException("Nullable is not allowed for element : RiketeInfo");
            }
            Writer.WriteEndElement();
        }
        
        public override void ReadXml(global::Xtee.Core.IXteeXmlReader Reader) {
            base.ReadXml(Reader);
        START:
            if ((Reader.LocalName == "yv_liik")) {
                goto yv_liik;
            }
            else {
                if ((Reader.LocalName == "yv_kp")) {
                    goto yv_kp;
                }
                else {
                    if ((Reader.LocalName == "jargm_yv_kp")) {
                        goto jargm_yv_kp;
                    }
                    else {
                        if ((Reader.LocalName == "yv_markus")) {
                            goto yv_markus;
                        }
                        else {
                            if ((Reader.LocalName == "rikked")) {
                                goto rikked;
                            }
                            else {
                                if ((Reader.LocalName == "rikete_info")) {
                                    goto rikete_info;
                                }
                                else {
                                    return;
                                }
                            }
                        }
                    }
                }
            }
        yv_liik:
            if (Reader.IsElementNil()) {
                throw new global::Xtee.Core.Exceptions.NillableNotAllowedException(">>ylevaatus>yv_liik");
            }
            clazz.YvLiik = new global::Xtee.Core.Schema.XsdString(Reader.ReadElementString("yv_liik")).Value;
            goto START;
        yv_kp:
            if (Reader.IsElementNil()) {
                throw new global::Xtee.Core.Exceptions.NillableNotAllowedException(">>ylevaatus>yv_kp");
            }
            clazz.YvKp = new global::Xtee.Core.Schema.XsdString(Reader.ReadElementString("yv_kp")).Value;
            goto START;
        jargm_yv_kp:
            if (Reader.IsElementNil()) {
                throw new global::Xtee.Core.Exceptions.NillableNotAllowedException(">>ylevaatus>jargm_yv_kp");
            }
            clazz.JargmYvKp = new global::Xtee.Core.Schema.XsdString(Reader.ReadElementString("jargm_yv_kp")).Value;
            goto START;
        yv_markus:
            if (Reader.IsElementNil()) {
                throw new global::Xtee.Core.Exceptions.NillableNotAllowedException(">>ylevaatus>yv_markus");
            }
            clazz.YvMarkus = new global::Xtee.Core.Schema.XsdString(Reader.ReadElementString("yv_markus")).Value;
            goto START;
        rikked:
            if (Reader.IsElementNil()) {
                throw new global::Xtee.Core.Exceptions.NillableNotAllowedException(">>ylevaatus>rikked");
            }
            global::Xtee.Core.SerializationMetadata metaRikked = this.GetMetaData<Ylevaatus.IRikkedType>(Reader, ">>ylevaatus>rikked", "http://producers.liiklusregister.xtee.riik.ee/producer/liiklusregister");
            clazz.Rikked = metaRikked.NewEntity<Ylevaatus.IRikkedType>();
            if ((Reader.IsEmptyElement == false)) {
                Reader.ReadStartElement("rikked");
                metaRikked.NewSerializer(clazz.Rikked).ReadXml(Reader);
                Reader.ReadEndElement();
            }
            else {
                Reader.Skip();
            }
            goto START;
        rikete_info:
            if (Reader.IsElementNil()) {
                throw new global::Xtee.Core.Exceptions.NillableNotAllowedException(">>ylevaatus>rikete_info");
            }
            clazz.RiketeInfo = new global::Xtee.Core.Schema.XsdString(Reader.ReadElementString("rikete_info")).Value;
            goto START;
        }
        
        [global::Xtee.Core.Attributes.XmlTypeAttribute(Name=">>ylevaatus>rikked", Namespace="http://producers.liiklusregister.xtee.riik.ee/producer/liiklusregister", Target=typeof(Ylevaatus.RikkedType))]
        public class RikkedTypeSerializer : global::Xtee.Core.Types.AbstractXteeSerializable {
            
            protected Ylevaatus.IRikkedType clazz;
            
            public RikkedTypeSerializer(Ylevaatus.IRikkedType clazz) {
                this.clazz = clazz;
            }
            
            public override void WriteXml(global::Xtee.Core.IXteeXmlWriter Writer) {
                base.WriteXml(Writer);
                for (int x = 0; ((clazz.Rike != null) 
                            && (x < clazz.Rike.Count)); x = (x + 1)) {
                    if (clazz.Rike[x]!=null) {
                        Writer.WriteStartElement("rike");
                        global::Xtee.Core.SerializationMetadata metaRike = this.GetMetaData(clazz.Rike[x]);
                        Writer.WriteTypeAttribute(metaRike.TypeQualifiedName.Namespace, metaRike.TypeQualifiedName.Name);
                        metaRike.NewSerializer(clazz.Rike[x]).WriteXml(Writer);
                        Writer.WriteEndElement();
                    }
                }
            }
            
            public override void ReadXml(global::Xtee.Core.IXteeXmlReader Reader) {
                base.ReadXml(Reader);
                if (Reader.LocalName=="rike") {
                    clazz.Rike = new System.Collections.Generic.List<global::Producers.Liiklusregister.Xtee.Riik.Ee.Producer.Liiklusregister.IYlevaatusRike>();
                    for (; ((Reader.NodeType != System.Xml.XmlNodeType.EndElement) 
                                && (Reader.LocalName == "rike")); ) {
                        if (Reader.IsElementNil()) {
                            throw new global::Xtee.Core.Exceptions.NillableNotAllowedException(">>>ylevaatus>rikked>rike");
                        }
                        global::Xtee.Core.SerializationMetadata metaRike = this.GetMetaData<global::Producers.Liiklusregister.Xtee.Riik.Ee.Producer.Liiklusregister.IYlevaatusRike>(Reader, "ylevaatus_rike", "http://producers.liiklusregister.xtee.riik.ee/producer/liiklusregister");
                        global::Producers.Liiklusregister.Xtee.Riik.Ee.Producer.Liiklusregister.IYlevaatusRike item = metaRike.NewEntity<global::Producers.Liiklusregister.Xtee.Riik.Ee.Producer.Liiklusregister.IYlevaatusRike>();
                        clazz.Rike.Add(item);
                        if ((Reader.IsEmptyElement == false)) {
                            Reader.ReadStartElement("rike");
                            metaRike.NewSerializer(item).ReadXml(Reader);
                            Reader.ReadEndElement();
                        }
                        else {
                            Reader.Skip();
                        }
                    }
                }
            }
        }
    }
}
